package com.bby.common.utils;


import lombok.Data;
import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
public class R{
    Integer code;
    String msg;
    String status;
    Object data;
    public R() {
        code = StatusCode.OK;
        status="success";
    }
    public R(int code,String msg) {
        this.code=code;
        this.msg=msg;
        if (code!=StatusCode.OK){
            status="error";
        }
    }

    public static R error(){
        return error(StatusCode.UNKNOWN_ERROR,"未知异常，请联系管理员！");
    }
    public static R error (String msg) {
        return error(StatusCode.UNKNOWN_ERROR,msg);
    }
    public static R error (int code,String msg) {
        return error(code).setMsg(msg);
    }
    public static R error (int code) {
        return new R().setCode(code).setStatus("error");
    }

    public static R ok () {return new R();}
//    public static R ok (String msg) {
//        return new R().setMsg(msg);
//    }
    public static R ok (Object data) {
        return new R(data);
    }
    public R(Object data){
        this.data=data;
        code = StatusCode.OK;
        status="success";
    }
}
